package cn.afterturn.easypdf.pdf.entity.base;

import lombok.Data;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.vandeseer.easytable.structure.Table;

/**
 * pdf页面相关信息
 */
@Data
public class PdfPageInfo {

    private PDPage page;

    private PDPageContentStream contentStream;

    private Table.TableBuilder table;

    private float width;

    private float height;

    private float startX = 20F;

    private float startY = 20F;

    private float currentHeight = 20F;

    public void setHeightAndY(float currentHeight) {
        this.currentHeight = currentHeight;
        this.startY = currentHeight;
    }

    public float getRealStartY() {
        return page.getMediaBox().getUpperRightY() - getStartY();
    }

    public float getRealStartY(float startY) {
        if (startY == -999) {
            return page.getMediaBox().getUpperRightY() - getStartY();
        }
        return page.getMediaBox().getUpperRightY() - startY;
    }
}
